package cn.wit.summit.chwan.widgets;

import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.utils.StringUtils;

/**
 * Created by tangbl on 2018/4/20.
 */

public class MessageDialog extends AlertDialog {

    private TextView dialogMessageTitleTx;
    private TextView dialogMessageContentTx;
    private Button dialogMessageCancelBt;
    private Button dialogMessageOkBt;

    private LinearLayout dialogMessageTagLl;
    private SimpleDraweeView dialogMessageTagIv;
    private TextView dialogMessageTagTx;
    private ImageView cancelIv;

    public MessageDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setCancelable(false);  //是否获取界外焦点
        Window dialogWindow = getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.CENTER);
        setContentView(R.layout.dialog_message_view);
        dialogMessageTitleTx = findViewById(R.id.dialogMessageTitleTx);
        dialogMessageContentTx = findViewById(R.id.dialogMessageContentTx);
        dialogMessageCancelBt = findViewById(R.id.dialogMessageCancelBt);
        dialogMessageOkBt = findViewById(R.id.dialogMessageOkBt);

        dialogMessageTagLl = findViewById(R.id.dialogMessageTagLl);
        dialogMessageTagIv = findViewById(R.id.dialogMessageTagIv);
        dialogMessageTagTx = findViewById(R.id.dialogMessageTagTx);
        cancelIv = findViewById(R.id.cancelIv);

    }

    public void showTopCancle(){
        cancelIv.setVisibility(View.VISIBLE);
        cancelIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    public void setModelLl(String icon, String text) {
        dialogMessageTagLl.setVisibility(View.VISIBLE);
        if (!StringUtils.isEmpty(icon))
            dialogMessageTagIv.setImageURI(icon);
        dialogMessageTagTx.setText(Html.fromHtml(text));
    }

    public void setCancelBtn(String txt, View.OnClickListener clickListener) {
        dialogMessageCancelBt.setOnClickListener(clickListener);
        dialogMessageCancelBt.setText(txt);
    }

    public void setOkBtn(String txt, View.OnClickListener clickListener) {
        dialogMessageOkBt.setOnClickListener(clickListener);
        dialogMessageOkBt.setText(txt);
    }

    public void setMsg(String txt) {
        dialogMessageContentTx.setText(txt);
    }

    public void setTitle(String txt) {
        dialogMessageTitleTx.setText(txt);
    }

}
